package com.eastfair.point.listener;

import com.alibaba.fastjson.JSON;
import com.eastfair.cache.repository.CachePlusOps;
import com.eastfair.mq.model.MySimpleMessage;
import com.eastfair.mq.service.OrderBusinessPointService;
import com.eastfair.mq.util.MessageExtUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 多功能串联
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "${rocketmq.consumer.orderConsumer}", consumerGroup = "${rocketmq.consumer.orderConsumerConsumer}",
        messageModel = MessageModel.CLUSTERING, consumeMode = ConsumeMode.ORDERLY)
public class OrderBusinessPointListner implements RocketMQListener<MySimpleMessage> {
    @Autowired
    private OrderBusinessPointService orderBusinessPointService;
    @Autowired
    private CachePlusOps cachePlusOps;

    @Autowired
    private MessageExtUtil messageExtUtil;
    @Override
    public void onMessage(MySimpleMessage message) {
        if (message==null) {
            return;
        }
        //消息是否已经消费
        if (messageExtUtil.isUseMessage(message)) {
            return;
        }
        log.info("多功能串联："+JSON.toJSONString(message));
        //记录日志：顺序写随机读 单向发送
        orderBusinessPointService.execute(message);
        //清空缓存key
        messageExtUtil.removeKey(message);

    }

}
